package com.accenture.fd.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.accenture.fd.dao.AnotationUserDao;
import com.accenture.fd.dao.AuthorityDao;
import com.accenture.fd.dao.ClassListDao;
import com.accenture.fd.dao.Cm00004Dao;
import com.accenture.fd.dao.DesignTblDao;
import com.accenture.fd.dao.ItemControlDao;
import com.accenture.fd.dao.LogicalDataItemDao;
import com.accenture.fd.dao.ProcessListDao;
import com.accenture.fd.dao.ScreenItemDescriptionTblDao;
import com.accenture.fd.entity.AuthorityEntity;
import com.accenture.fd.entity.ClassListEntity;
import com.accenture.fd.entity.Cm00004;
import com.accenture.fd.entity.DesignEntity;
import com.accenture.fd.entity.ItemControlEntity;
import com.accenture.fd.entity.LogicalDataItemEntity;
import com.accenture.fd.entity.ScreenItemDescriptionEntity;
import com.accenture.fd.entity.UploadFileForProcessListEntity;
import com.accenture.fd.entity.User;
import com.accenture.fd.service.ImportExcelToDBService;

@Service
public class ImportExcelToDBServiceImpl implements ImportExcelToDBService {

	@Autowired
	private AnotationUserDao userDao;

	@Autowired
	private ScreenItemDescriptionTblDao screenItemDescriptionTblDao;

	@Autowired
	private DesignTblDao designTblDao;

	@Autowired
	private LogicalDataItemDao logicalDataItemDao;

	@Autowired
	private ProcessListDao processListDao;

	@Autowired
	private ClassListDao classListDao;
	
	@Autowired
	private AuthorityDao authorityDao;

	@Autowired
	private ItemControlDao itemContolDao;

	@Autowired
	private Cm00004Dao cm00004Dao;
	
	@Override
	public void saveUserAll(List<User> userList) {
		userDao.saveAll(userList);
	}

	@Override
	public void saveScreenItemDescription(List<ScreenItemDescriptionEntity> entityList) {
		screenItemDescriptionTblDao.delFromScreenItemDescriptionTable(entityList.get(0).getScreenId(), entityList.get(0).getDesignTypeId());
		screenItemDescriptionTblDao.saveScreenItemDescriptionEntityList(entityList);

	}

	@Override
	public void saveDesign(List<DesignEntity> designEntityList) {
		designTblDao.delFromDesignTable(designEntityList.get(0).getScreenId(), designEntityList.get(0).getDesignTypeId());
		designTblDao.saveDesignEntityList(designEntityList);
	}

	@Override
	public void saveLogicalDataItem(List<LogicalDataItemEntity> entityList) {
		logicalDataItemDao.truncateLogicalDataItem();
		logicalDataItemDao.saveLogicalDataItem(entityList);
	}

	@Override
	public void saveScreenPrcessList(List<UploadFileForProcessListEntity> subList) {
		processListDao.truncate();
		processListDao.saveAll(subList);

	}

	@Override
	public void saveScreenClassListDescription(List<ClassListEntity> classListEntityList) {
		classListDao.delAllClassList();	
		classListDao.saveAllClassList(classListEntityList);
	}
	
	@Override
	public List<String> selAuthority(String screenId) {
		return authorityDao.selFromAuthorityTable(screenId);
	}
	
	@Override
	public void delAuthority(String screenId) {
		authorityDao.delFromAuthorityTable(screenId);
	}
	
	@Override
	public void saveAuthority(List<AuthorityEntity> entityList) {
		authorityDao.saveAuthorityEntityList(entityList);
	}

	@Override
	public void saveControl(List<ItemControlEntity> controlList) {
		itemContolDao.saveAll(controlList);
	}
	
	@Override
	public void delItemControlByScreenId(String screenId) {
		itemContolDao.delItemControlByScreenId(screenId);
	}
	
	@Override
	public List<String> selectItemControlByScreenId(String screenId) {
		return itemContolDao.selectItemControlByScreenId(screenId);
	}
	
	@Override
	public HashMap<String, String> getAllDateList() {
		HashMap<String, String> returnValue = new HashMap<String, String>();
		List<Cm00004> cm00004List = cm00004Dao.getAllDateList();
		for (Cm00004 cm00004 : cm00004List) {
			returnValue.put(cm00004.getJpnNm(), cm00004.getEngNm());
		}
		return returnValue;
	}
}
